package 力扣日常刷题.木23一月.第20天320;

public class Demo105 {


    public int countHillValley(int[] nums) {
        int ans = 0;

        //flag = 2 表示前面上升

        int flag = 0;

        for (int i = 1; i < nums.length; i++) {
            if(nums[i] > nums[i-1]){
                if(flag == 1) ans ++;
                flag = 2;
            }else if(nums[i] < nums[i-1]){
                if(flag == 2) ans ++;
                flag = 1;
            }
        }
        return ans;
    }
}
